﻿@{
    Layout = null;
}
<!DOCTYPE html>
<html>
<head>
    <title>Index</title>
    <script src='@Url.Content("~/Scripts/PageCreater/Scripts/jquery-1.5.1.min.js")' type="text/javascript"></script>
    <link href='@Url.Content("~/Scripts/zTree/css/zTreeStyle/zTreeStyle.css")' rel="stylesheet" type="text/css" />
    <script src='@Url.Content("~/Scripts/zTree/js/jquery.ztree.core-3.5.js")' type="text/javascript"></script>
    <script src='@Url.Content("~/Scripts/PageCreater/Scripts/PageCreater.js")' type="text/javascript"></script>
    <link href='@Url.Content("~/Scripts/PageCreater/Css/Style.css")' rel="stylesheet" type="text/css" />
    <script type="text/javascript">
        $(document).ready(function () {
            $.ajaxSetup({ cache: false });
            var str = "Term,学期,false,text,notnull,"
                        + "FullMarks,总分,false,text,notnull,"
                        + "StartTime,开始时间,false,text|date,notnull,"
                        + "EndTime,结束时间,false,text|date,notnull,"
                        + "Opreate,操作,false,null,null";
//            var strOpreate = "开始评教,/User/Update,true,切换状态,/User/Withdraw,false";
//            CreateIndexPage("/User/GetPaged", strColumn, strOpreate);
            //CreatePageFram(str);
            $.fn.zTree.init($("#deparentmentTree"), treeSetting, treeNodes);
        })

        var treeNodes = [
			{ id: 1, pid: 0, name: "请选择系部", isParent: true, icon: "../../Scripts/zTree/css/zTreeStyle/img/diy/users.png" }
		];

			var treeSetting = {
			    async: {
			        enable: true,
			        url: "/Evaluate/GetOrganizations",
			        type: "Get",
			        dataType: "json",
			        autoParam: ["id", "pid", "name", "level"]
			    },
			    callback: {
			        onAsyncSuccess: function (event, treeId, treeNode, msg) {
			        },
			        onAsyncError: function (event, treeId, treeNode, XMLHttpRequest, textStatus, errorThrown) {
			            alert(errorThrown);
			        },
			        beforeExpand: beforeExpand,
			        onExpand: onExpand,
			        onClick: onClick,
			        onCheck: function (event, treeId, treeNode) {
			            if (treeNode.checked == true) {
			                if (treeNode.level == 0) {
			                    if (treeNode.children == null) {
			                        treeNode.checked = false;
			                        alert("请先展开列表！");
			                    }
			                }
			            }
			        }
			    }
			};

        function createNodes(maxNodesNumInLevel, maxLevel, curLevel, curPId) {
            if (maxNodesNumInLevel < 5) {
                maxNodesNumInLevel = 5;
            }
            var nodes = [], num = 0;
            while (num < 3) {
                num = parseInt(Math.random() * 1024) % maxNodesNumInLevel + 1;
            }
            for (var i = 0; i < num; i++) {
                var id = curPId ? curPId + "-" + i : "" + i, isParent = (parseInt(Math.random() * 9999) % 3 != 0),
				node = { id: id, pId: curPId, name: "N" + id };
                nodes.push(node);
                if (isParent && curLevel < maxLevel) {
                    nodes = nodes.concat(createNodes(maxNodesNumInLevel, maxLevel, curLevel + 1, id));
                }
            }
            return nodes;
        }
        var zNodes = createNodes(5, 5, 0);

        var curExpandNode = null;

        function beforeExpand(treeId, treeNode) {
            var pNode = curExpandNode ? curExpandNode.getParentNode() : null;
            var treeNodeP = treeNode.parentTId ? treeNode.getParentNode() : null;
            var zTree = $.fn.zTree.getZTreeObj("roleTree");
            for (var i = 0, l = !treeNodeP ? 0 : treeNodeP.children.length; i < l; i++) {
                if (treeNode !== treeNodeP.children[i]) {
                    zTree.expandNode(treeNodeP.children[i], false);
                }
            }
            while (pNode) {
                if (pNode === treeNode) {
                    break;
                }
                pNode = pNode.getParentNode();
            }
            if (!pNode) {
                singlePath(treeNode);
            }

        }

        function singlePath(newNode) {
            if (newNode === curExpandNode) return;
            if (curExpandNode && curExpandNode.open == true) {
                var zTree = $.fn.zTree.getZTreeObj("roleTree");
                if (newNode.parentTId === curExpandNode.parentTId) {
                    zTree.expandNode(curExpandNode, false);
                } else {
                    var newParents = [];
                    while (newNode) {
                        newNode = newNode.getParentNode();
                        if (newNode === curExpandNode) {
                            newParents = null;
                            break;
                        } else if (newNode) {
                            newParents.push(newNode);
                        }
                    }
                    if (newParents != null) {
                        var oldNode = curExpandNode;
                        var oldParents = [];
                        while (oldNode) {
                            oldNode = oldNode.getParentNode();
                            if (oldNode) {
                                oldParents.push(oldNode);
                            }
                        }
                        if (newParents.length > 0) {
                            zTree.expandNode(oldParents[Math.abs(oldParents.length - newParents.length) - 1], false);
                        } else {
                            zTree.expandNode(oldParents[oldParents.length - 1], false);
                        }
                    }
                }
            }
            curExpandNode = newNode;
        }

        function onExpand(event, treeId, treeNode) {
            curExpandNode = treeNode;
        }

        function onClick(e, treeId, treeNode) {
            var zTree = $.fn.zTree.getZTreeObj("roleTree");
            zTree.expandNode(treeNode, null, null, null, true);
        }
    </script>
</head>
<body style=" margin:0px; border:0px;">
    <div>
        <div style=" float:left;">
            <ul id="deparentmentTree" class="ztree">
            </ul>
        </div>
        <div id="divContent" style=" float:left;">
        </div>
    </div>
</body>
</html>
